package com.example.pda.ui.query;

import com.example.pda.common.BaseViewModel;
import com.example.pda.common.Utils;
import com.example.pda.data.Result;
import com.example.pda.data.model.GoodItem;
import com.example.pda.data.model.Inventory;
import com.example.pda.data.model.PurchaseOrder;
import com.example.pda.data.model.StoreBean;

import java.util.ArrayList;
import java.util.List;

import androidx.lifecycle.MutableLiveData;

public class QueryViewModel extends BaseViewModel {
    public MutableLiveData<List<StoreBean>> mBeans = new MutableLiveData<>();

    public MutableLiveData<PurchaseOrder> mPurchaseBean = new MutableLiveData<>();

    public void loadOrderQuery(String type, String text) {
        if(type.equals("order")){
            enqueue(api.getSoOrder(text), true, new ResultCallback<PurchaseOrder>() {
                @Override
                public void onSuccess(PurchaseOrder purchaseOrder) {
                    mPurchaseBean.setValue(purchaseOrder);
                    if(purchaseOrder == null){
                        Utils.getInstance().showToast("暂未查询到数据");
                    }
                }

                @Override
                public void onError(int code, String msg) {
                    mPurchaseBean.setValue(new PurchaseOrder());
                    Utils.getInstance().showToast(msg);
                }
            });
        } else {
            enqueue(api.getOnhandnum(text), true, new ResultCallback<List<StoreBean>>() {
                @Override
                public void onSuccess(List<StoreBean> items) {
                    mBeans.setValue(items);
                    if(Utils.isEmpty(items)){
                        Utils.getInstance().showToast("查无此单号");
                    }
                }

                @Override
                public void onError(int code, String msg) {
                    mBeans.setValue(null);
                    Utils.getInstance().showToast(msg);
                }
            });
        }
    }
}
